$('#formSignin').on('submit', function(e) {
    var details = $('#formSignin').serialize();
    var username = $('#name').val();
    var pass = $('#pwd').val();
    var confirm_pass = $('#confirm-pwd').val();
    var email = $('email').val();
    var phone = $('phone').val();
    var birthday = $('age').val();
    var id = $('idcard').val();
    var url = 'http://uneven.live:8080/registered';
    var $status = $('#status');
    var $submitButton = $('#submit');
    e.preventDefault();
    /*Check all input */
    if (!username || !pass || !confirm_pass ||
        !email || !phone || !birthday || !id) {
        $status.html('<div class="error-status">请完整填写所有信息</div>');
        return;
    }
    if (pass !== confirm_pass) {
        $status.html('<div class="error-status">密码不一致</div>');
        return;
    }
    var valid = /[^@]+@[^@]+/.test(email);
    if (!valid) {
        $status.html('<div class="error-status">请提供有效的邮箱地址</div>');
        return;
    }
    valid = /^\d+$/.test(id);
    if (!valid) {
        $status.html('<div class="error-status">请提供有效的身份证号</div>');
        return;
    }

    $.ajax({
        type: "POST",
        url: url,
        timeout: 3000,
        data: details,
        beforeSend: function() {
            $submitButton.addClass('hide');
            $status.append('<div class="status">请等待……</div>');
        },
        complete: function() {
            $('div.status').remove();
        },
        success: function(data) {
            if (data.Code == 0) {
                $status.html('<div class="status">注册成功！<br>请进入您的邮箱完成验证！ヾ(≧▽≦*)o</div>');
            } else {
                $submitButton.removeClass('hide');
                $status.html('<div class="error-status">' + data.Msg + '</div>');
            }
        },
        fail: function() {
            $submitButton.removeClass('hide');
            $status.html('<div class="error-status">无法连接服务器，请稍后再试</div>');
        }
    });
});